

var minDepth = function (root) {
    if (root === null) {
        return 0
    }
    let leftHeight = minDepth(root.left)
    let rightHeight = minDepth(root.right)

    if (root.left === null && root.right !== null) {
        return 1 + rightHeight
    }
    if (root.left !== null && root.right === null) {
        return 1 + leftHeight
    }
    let minHeight = 1 + math.min(leftHeight, rightHeight)
    return minHeight
};